package com.example.admin.testdemo.util;

import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

public class HandleMonitorResult {

    public static void showInfo(AppCompatActivity context, byte[] data) {
        showToast(context, getInfo(data));
    }


    private static String getInfo(byte[] buff) {
        String info = "待定义";
        if (buff[0] == (byte) 0x3B && buff[1] == (byte) 0xB3 && buff[5] == (byte) 0xA6 && buff[14] == (byte) 0x01) {
            info = "流水号重复";
        } else if (buff[0] == (byte) 0x3B && buff[1] == (byte) 0xB3 && buff[5] == (byte) 0xA6 && buff[14] == (byte) 0x02) {
            info = "电机等待转动";
        } else if (buff[0] == (byte) 0x3B && buff[1] == (byte) 0xB3 && buff[5] == (byte) 0xA6 && buff[14] == (byte) 0x03) {
            info = "待定义";
        } else if (buff[0] == (byte) 0x3B && buff[1] == (byte) 0xB3 && buff[5] == (byte) 0xA6 && buff[14] == (byte) 0x00) {
            info = "电机开始转动";
        }
        return info;
    }

    private static void showToast(final AppCompatActivity context, final String msg) {
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
